package cs294s.liveradar;


import cs294s.liveradar.data.Blip;
import cs294s.liveradar.service.Feed;
import cs294s.liveradar.service.FeedManager;
import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ListView;

public class BlipList extends ListActivity{
	
	
	FeedManager mFeedManager;
    Feed feed;
    int feedPosition = 0;
	
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
	  //ignore orientation change
	  super.onConfigurationChanged(newConfig);
	}

	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
	    super.onCreate(savedInstanceState);

        ListView listView = getListView();
        listView.setBackgroundDrawable(null);
        
        
	    feedPosition = getIntent().getIntExtra("feedPosition", -1);
	    
	    mFeedManager = FeedManager.getInstance(this);
	   
	    if(feedPosition == -1) {
	    	
	    	setListAdapter(new GlobalBlipAdapter(this));
	    } else {
	    	 feed = mFeedManager.get(feedPosition);
	    	setListAdapter(new BlipAdapter(this, feedPosition));
	    }
        mFeedManager.updateFeeds();
        
        
	}
	
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        
    	Blip b;
    	if(feedPosition < 0)
    		b = mFeedManager.linearMappingGet(position);
    	else 
    		b = feed.get(position);
        
        /*Go to Blip's location on Map*/
        Intent i = new Intent(this, RadarMap.class);
        i.putExtra("lat", b.getLocation().getLatitudeE6());
        i.putExtra("lon", b.getLocation().getLongitudeE6());
        startActivity(i);
    }   
}
